﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.Currency
{
    public class CurrencyPresenter : Presenter<ICurrencyView>
    {
        public CurrencyPresenter(ICurrencyView view)
            : base(view)
        {
        }

        public void Display(string currencyId)
        {
            if (currencyId == null) return;

            var currency = Model.GetCurrency(currencyId);

            View.CurrencyID = currency.CurrencyID;
            View.CurrencyCode = currency.CurrencyCode;
            View.CurrencyName = currency.CurrencyName;
            View.Description = currency.Description;
            View.IsActive = currency.IsActive;
        }

        public int Save()
        {
            var currency = new CurrencyModel
            {
                CurrencyID = View.CurrencyID,
                CurrencyCode = View.CurrencyCode,
                CurrencyName = View.CurrencyName,
                Description = View.Description,
                IsActive = View.IsActive
            };

            if (View.CurrencyID == null)
                return Model.AddCurrency(currency);
            else
                return Model.UpdateCurrency(currency);
        }

        public int Delete(string currencyId)
        {
            return Model.DeleteCurrency(currencyId);
        }
    }
}
